<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\index\controller;
use app\common\controller\ControllerBase;
/**
 * 前端首页控制器
 */
class Index extends ControllerBase
{
    // 首页
    public function index()
    {
    	$this->view->engine->layout(false);
        echo "<script>window.location.href='http://www.chinawylm.com/index/';</script>";exit;
        if($this->isMobile()){
            return $this->fetch('index');
        }else{
            return $this->fetch('indexs');
        }
    }
    //判断是否手机页面访问
    public function isMobile(){
        // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
        if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])){
            return TRUE;
        }
        // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
        if (isset ($_SERVER['HTTP_VIA'])){
            return stristr($_SERVER['HTTP_VIA'], "wap") ? TRUE : FALSE;// 找不到为flase,否则为TRUE
        }
        // 判断手机发送的客户端标志,兼容性有待提高
        if (isset ($_SERVER['HTTP_USER_AGENT'])) {
            $clientkeywords = array (
                'mobile',
                'nokia',
                'sony',
                'ericsson',
                'mot',
                'samsung',
                'htc',
                'sgh',
                'lg',
                'sharp',
                'sie-',
                'philips',
                'panasonic',
                'alcatel',
                'lenovo',
                'iphone',
                'ipod',
                'blackberry',
                'meizu',
                'android',
                'netfront',
                'symbian',
                'ucweb',
                'windowsce',
                'palm',
                'operamini',
                'operamobi',
                'openwave',
                'nexusone',
                'cldc',
                'midp',
                'wap'
            );
            // 从HTTP_USER_AGENT中查找手机浏览器的关键字
            if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))){
                return TRUE;
            }
        }
        if (isset ($_SERVER['HTTP_ACCEPT'])){ // 协议法，因为有可能不准确，放到最后判断
            // 如果只支持wml并且不支持html那一定是移动设备
            // 如果支持wml和html但是wml在html之前则是移动设备
            if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== FALSE) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === FALSE || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))){
                return TRUE;
            }
        }
        return FALSE;
    }
    // 详情
    public function details($id = 0)
    {
        $this->view->engine->layout(false);
        $where = [];
        
        !empty((int)$id) && $where['a.id'] = $id;
        
        $data = $this->logicArticle->getArticleInfo($where);
        
        $this->assign('article_info', $data);
        
        $this->assign('category_list', $this->logicArticle->getArticleCategoryList([], true, 'create_time asc', false));
        
        return $this->fetch('details');
    }
    // 首页
    public function sh_job()
    {
    	$this->view->engine->layout(false);
        $data=$this->param;
        $id=$data['wid'];
        $info=db('work')->where('id',$id)->find();
        $info['cont']=preg_replace('/\n/', '<br>', $info['cont']);
        $info['education']=db('education')->where('education_id',$info['education_id'])->value('name');
        $info['experience']=db('experience')->where('experience_id',$info['experience_id'])->value('name');
        if(!empty($info['position_id'])){
            $info['position']=db('position_cat')->where('id',$info['position_id'])->value('catname');
        }
        $cinfo=db('company')->field('company,type,num')->where('user_id',$info['user_id'])->find();
        $cinfo['typeName']=db('company_type')->where('id',$cinfo['type'])->value('name');
        $cinfo['numName']=db('company_num')->where('id',$cinfo['num'])->value('name');
        $cinfo['headimg']=db('user')->where('id',$info['user_id'])->value('headimg');
        $this->assign('info', $info);
        $this->assign('cinfo', $cinfo);
        return $this->fetch('jobInfo');
    }
    //简历详情
    public function resumeInfo(){
    	$this->view->engine->layout(false);
        $data=$this->param;
        $data['user_id']=10006;
        $info=db('resume')->where(array('user_id'=>$data['user_id']))->find();
        $info['cont']=preg_replace('/\n/', '<br>', $info['cont']);
        if(!empty($info['position_id'])){
            $info['positionName']=db('position_cat')->where('id',$info['position_id'])->value('catname');
        }
        if(!empty($info['education_id'])){
            $info['education']=db('education')->where('education_id',$info['education_id'])->value('name');
        }
        $info['headimg']=db('user')->where('id',$info['user_id'])->value('headimg');
        $info['age']=countages($info['birthday']);
        $info['gzjy']=countages($info['joinTime']);
        $info['experienceList']=db('resume_experience')->where('resume_id',$info['resume_id'])->select();
        $info['educationList']=db('resume_education')->where('resume_id',$info['resume_id'])->select();
        $this->assign('info', $info);
        return $this->fetch('resumeInfo');
    }
//    //测试推送
//    public function tuisong(){
//        $res=jpush('10006',4,'恭喜您，您有新的MDC到账啦！');
//        var_dump($res);exit;
//    }
//    //测试rsa
//    public function rsajm(){
//        $public='/www/wwwroot/app.lptxhr.com/public/rsa/pub.key';
//        $pravite='/www/wwwroot/app.lptxhr.com/public/rsa/priv.key';
//        import("rsa.Rsa");
//        $rsa = new \Rsa($public,$pravite);
//        $str=$rsa->encrypt('10006');
//        var_dump($str);exit;
//    }
//    /**
//     * 邮件发送
//     */
    public function demoSendEmail()
    {
        $str="内容";
        $data = send_email('296411083@qq.com', '诸葛聘', $str);
        var_dump($data);exit;
    }
    /**
     * 火币接口
    */
    public function hbsearch(){

        $config=[
            "apiKey"=>"a69416d7-8994-4768-9ce0-495cf67d580e",
            "apiSecret"=>"5FAF5885A5892C16CB2605C3D68F3659",
            "passphrase"=>"hqhy1106",
        ];
        import("hb.SwapApi");
        $instrumentId = "EOS-USD-SWAP";
        $rsa = new \SwapApi($config);
        $s=$rsa->getSpecificPosition($instrumentId);
        var_dump($s);exit;
    }
    public function mysqlSave(){
        import("wechat.Jssdk");
        $jssdk  = new \Jssdk('wx3f6de126bb13ca05','8fb3d29df80e1042f182c7787d748ed7');
        $signPackage = $jssdk->getSignPackage();
        var_dump($signPackage);exit;
        //$arr=db('goods_cat')->where("pid = 0")->column('id');
        //db('goods_cat')->where("pid IN(".implode(',',$arr).")")->update(['level'=>2]);
    }
}
